package com.ruoyi.project.per.app.content.controller;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.per.app.content.domain.AppContent;
import com.ruoyi.project.per.app.content.domain.AppContentVo;
import com.ruoyi.project.per.app.content.service.IAppContentService;
import com.ruoyi.project.per.app.type.domain.AppType;
import com.ruoyi.project.per.app.type.service.IAppTypeService;
import com.ruoyi.project.per.emp.domain.Emp;
import com.ruoyi.project.per.emp.service.IEmpService;
import com.ruoyi.project.system.post.domain.Post;
import com.ruoyi.project.system.post.service.IPostService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 小新
 * @date 2020-09-19 19:31
 * @desc
 */
@Controller
@RequestMapping("/per/app/content")
public class AppContentController extends BaseController {
    private String prefix = "per/app/content";

    @Autowired
    private IAppContentService appContentService;

    @Autowired
    private IAppTypeService appTypeService;

    @Autowired
    private IEmpService empService;


    @RequiresPermissions("app:content:view")
    @GetMapping()
    public String operlog()
    {
        return prefix + "/content";
    }

    @RequiresPermissions("app:content:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppContentVo appContentVo)
    {
        startPage();
        List<AppContentVo> list = appContentService.selectAppContenttList(appContentVo);
        return getDataTable(list);
    }

    //根据id查询详细
    @GetMapping("/detail/{detail}")
    public String detail(@PathVariable("detail") Long detail, ModelMap mmap)
    {
        mmap.put("contents", appContentService.selectAppContentById(detail));
        return prefix + "/detail";
    }
    //根据id查询审批
    @GetMapping("/approve/{contentId}")
    public String approve(@PathVariable("contentId") Long contentId, ModelMap mmap)
    {
        mmap.put("contents", appContentService.selectAppContentById(contentId));
        return prefix + "/approve";
    }
    //根据id查询审批
    @RequestMapping("/approveUpdate")
    public String approveUpdate(Long contentId, ModelMap mmap)
    {

        return prefix + "/approve";
    }

    //新增申请
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("appTypes", appTypeService.selectAppTypeList(null));
        return prefix + "/add";
    }
    @PostMapping("/checkEmpId")
    @ResponseBody
    public Emp checkEmpId(String empId)
    {
         Long id= Long.valueOf(Integer.parseInt(empId));
        Emp emp = empService.selectEmpById(id);
        if (emp!=null){
            return emp;
        }
        Emp emp1=new Emp();
        emp1.setRemark("没有该员工");
        return emp1;
    }

    /**
     * 新增保存岗位
     */
    @RequiresPermissions("app:content:add")
    @Log(title = "申请内容管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated AppContent appContent)
    {

        return toAjax(appContentService.insertAppContent(appContent));
    }

}
